﻿/*
   Copyright 2013 Dmitry Bratus

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

using System.Collections.Generic;
using Flower.Services.Data;

namespace Flower.SqlServer.Directory.DbGenerator
{
    internal static class EntriesDefinition
    {
        public class EntryDefinition
        {
            public string Name { get; set; }
            public Dictionary<string, ColumnInfo> SpecificColumns { get; set; }
            public string SpecificInsertScriptResource { get; set; }
            public string SpecificUpdateScriptResource { get; set; }
            public string SpecificRemoveScriptResource { get; set; }
            public int DirectoryEntryType { get; set; }
        }

        public class ColumnInfo
        {
            public string Type { get; set; }
            public bool DontGenrateInsertUpdate { get; set; }
            public bool Readonly { get; set; }
        }

        public static readonly IEnumerable<EntryDefinition> Entries = new[] 
        {
            new EntryDefinition 
            {
                Name = "Assembly",
                DirectoryEntryType = (int)DirectoryEntryTypes.Assembly,
                SpecificColumns = new Dictionary<string, ColumnInfo> 
                {
                    { "Image", new ColumnInfo { Type = "varbinary(MAX)" } }
                }
            },
            new EntryDefinition 
            {
                Name = "Folder",
                DirectoryEntryType = (int)DirectoryEntryTypes.Folder,
            },
            new EntryDefinition 
            {
                Name = "Link",
                DirectoryEntryType = (int)DirectoryEntryTypes.Link,
                SpecificColumns = new Dictionary<string, ColumnInfo> 
                {
                    { "Target", new ColumnInfo { Type = "nvarchar(MAX)" } }
                }
            },
            new EntryDefinition 
            {
                Name = "Message",
                DirectoryEntryType = (int)DirectoryEntryTypes.Message,
                SpecificColumns = new Dictionary<string, ColumnInfo> 
                {
                    { "Data", new ColumnInfo { Type = "varbinary(MAX)" } },
                    { "DataFormat", new ColumnInfo { Type = "int" } },
                }
            },
            new EntryDefinition 
            {
                Name = "Process",
                DirectoryEntryType = (int)DirectoryEntryTypes.Process,
                SpecificColumns = new Dictionary<string, ColumnInfo> 
                {
                    { "Workflow", new ColumnInfo { Type = "nvarchar(MAX)" } }
                }
            },
            new EntryDefinition 
            {
                Name = "Processor",
                DirectoryEntryType = (int)DirectoryEntryTypes.Processor,
                SpecificColumns = new Dictionary<string, ColumnInfo> 
                {
                    { "Configuration", new ColumnInfo { Type = "varbinary(MAX)" } },
                    { "ConfigurationFormat", new ColumnInfo { Type = "int" } },
                }
            },
            new EntryDefinition 
            {
                Name = "Role",
                DirectoryEntryType = (int)DirectoryEntryTypes.Role,
                SpecificColumns = new Dictionary<string, ColumnInfo> 
                {
                    { "Users", new ColumnInfo { Type = "TNVarcharSet", DontGenrateInsertUpdate = true, Readonly = true } }
                },
                SpecificInsertScriptResource = "RoleUsersInsert",
                SpecificUpdateScriptResource = "RoleUsersUpdate",
                SpecificRemoveScriptResource = "RoleUsersDelete"
            },
            new EntryDefinition 
            {
                Name = "ServiceContainer",
                DirectoryEntryType = (int)DirectoryEntryTypes.ServiceContainer,
                SpecificColumns = new Dictionary<string, ColumnInfo> 
                {
                    { "Configuration", new ColumnInfo { Type = "varbinary(MAX)" } },
                    { "ConfigurationFormat", new ColumnInfo { Type = "int" } },
                }
            },
            new EntryDefinition 
            {
                Name = "Set",
                DirectoryEntryType = (int)DirectoryEntryTypes.Set,
                SpecificColumns = new Dictionary<string, ColumnInfo> 
                {
                    { "MessageType", new ColumnInfo { Type = "nvarchar(MAX)" } },
                    { "Capacity", new ColumnInfo { Type = "int" } },
                }
            },
            new EntryDefinition 
            {
                Name = "State",
                DirectoryEntryType = (int)DirectoryEntryTypes.State,
                SpecificColumns = new Dictionary<string, ColumnInfo> 
                {
                    { "Data", new ColumnInfo { Type = "varbinary(MAX)" } },
                    { "DataFormat", new ColumnInfo { Type = "int" } },
                }
            },
            new EntryDefinition 
            {
                Name = "Workflow",
                DirectoryEntryType = (int)DirectoryEntryTypes.Workflow,
                SpecificColumns = new Dictionary<string, ColumnInfo> 
                {
                    { "DefinitionType", new ColumnInfo { Type = "nvarchar(MAX)" } },
                    { "PreferredProcessors", new ColumnInfo { Type = "TNVarcharSet", DontGenrateInsertUpdate = true, Readonly = true } },
                },
                SpecificInsertScriptResource = "WorkflowPreferredProcessorsInsert",
                SpecificUpdateScriptResource = "WorkflowPreferredProcessorsUpdate",
                SpecificRemoveScriptResource = "WorkflowPreferredProcessorsDelete"
            },
        };
    }
}
